using System;
using System.Collections;
using System.Collections.Generic;


namespace SmallStepSemanticCsharp
{
    class MachineState
    {
        public MachineState(Statement stmt, Dictionary<string, int> env)
        {
            this.stmt = stmt;
            this.env = env;
        }
        public MachineState()
        {
 
        }
        public Statement stmt;
        public Dictionary<string, int> env;

    }
    class Machine
    {
        MachineState state = new MachineState();
        public Machine(Statement stmt, Dictionary<string, int> env)
        {
            state.stmt = stmt;
            state.env = env;

        }
        public void step()
        {
            state = state.stmt.reduce(state.env);
        }

        public void run()
        {
            while (state.stmt.reducible())
            {
                Console.Write(state.stmt);
                ShowEnv();

                step();
            }
            Console.Write(state.stmt);
            ShowEnv();

        }
        public void ShowEnv(){
            Console.Write("{");
            foreach (KeyValuePair<string, int> kv in state.env)   {
                Console.Write("{0}={1} ",kv.Key,kv.Value);
            }
            Console.WriteLine("}");
        }

    }

}